<?php
//检查字段是否存在
function pdo_fieldexists2($tablename, $fieldname){
    $fields = \think\facade\Db::query("SHOW COLUMNS FROM " . $tablename);
    if(empty($fields)){
        return false;
    }
    foreach ($fields as $field) {
        if ($fieldname == $field['Field']){
            return true;
        }
    }
    return false;
}

//检查表是否存在
function pdo_fieldexists3($tablename){
    $table = \think\facade\Db::query("SHOW TABLES LIKE '". $tablename."'");
    if(empty($table)){
        return false;
    }else{
        return true;
    }
}

if(!pdo_fieldexists2("unitp_users","test_u")) {
    \think\facade\Db::execute("ALTER TABLE `unitp_users` ADD COLUMN `test_u` varchar(60) DEFAULT NULL COMMENT '测试';");
}
?>